package org.jeecg.modules.front.util;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.text.DecimalFormat;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;
public class FundDate {
        public static boolean isOneFullMonth(Date date1, Date date2) {
            Calendar cal1 = Calendar.getInstance();
            Calendar cal2 = Calendar.getInstance();
            cal1.setTime(date1);
            cal2.setTime(date2);

            // 比较年份和月份
            return (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)) &&
                    (cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH));
        }

        //两个日期相差多少天
    public static long daysBetween(Date date1, Date date2) {

        // 使用ChronoUnit计算天数差
        long days=ChronoUnit.DAYS.between(date1.toInstant(), date2.toInstant());
        if(days>30)
        {
            return 30;
        }
        else
        {
            if(days>0)
            {
                return days;
            }
            else
            {
                return 0;
            }

        }

    }

    //相差一个月
    public static Boolean isOne(Date date1, Date date2)
    {
        // 示例：测试两个日期是否满一个月
        // 假设date2为下个月的同一天
        Calendar cal = Calendar.getInstance();
        cal.setTime(date1);
        cal.add(Calendar.MONTH, 1); // 将日期增加一个月
       return isOneFullMonth(cal.getTime(), date2);
    }


    //保留两位小数
    public static double DecimalFormatTwo(double number)
    {
        DecimalFormat df = new DecimalFormat("#.00");
        String formattedNumber = df.format(number);
        return Double.parseDouble(formattedNumber);
    }


    public static Date addMonths(Date date, int months) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, months);
        return calendar.getTime();
    }


    public static Date getTodayStartTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        return calendar.getTime();
    }


}
